home *** CD-ROM | disk | FTP | other *** search
- /*
- * xsgt.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /*
- * (e)X(tract) S(ite) G(eometry and) T(opology)
- *
- * routine to merge geometry and topology data for bubble patterns from:
- * -->files of type .gdt, generated by xah
- * -->files of type .std, generated by xvora
- * output file: .sgt
- *
- * various geometrical and topological quantities are evaluated:
- * -->p(n, A), joint coordination number, area distribution function
- * -->s_ij, distance of closest approach
- *
- */
-
- #include "sgt.h"
-
- #define MAX_RECORD_SIZE 600
-
-
- #define LINE_LEN 96 /* max length of line in data file */
- #define FN_LEN 16 /* length of data file name */
-
- #define ON 1
- #define OFF 0
- #define ECHO_FILE_NAME ON
-
- #define GDT_DEBUG
- #undef SHOW_HSORT
- #undef FRMS_DEBUG
- #undef KNNS_ARRAY_VER /* see comments in knns.c */
-
-
- /*
- * global variables
- */
- extern char *optarg;
- extern int optind, opterr;
-
- int READ_AFLAG = 0;
- int READ_GFLAG = 0;
- int CHECK_EDGE = 1;
- int WRITE_FILE = 0;
-
-
- #define BS_HIST "\nhistogram for boundary-separations"
- #define BIN_NUMBER 51 /* no bins in histogram */
- #define NSIJ_MIN 0.0 /* min, max for norm bound sep */
- #define NSIJ_MAX 2.5
-
- char *HIST_HEADER;
- int HIST_TYPE = -1;
- int N_BINS = BIN_NUMBER;
- int MIN_SET = 0;
- int MAX_SET = 0;
-
- int EVAL_KNN = 0;
- int SHOW_INPUT = 0;
- int SHOW_ALL = 1;
- int CONTRACT = 0;
-
-
- int KNN_MAX = 2; /* max nof NN shells to be constructed */
-
-
- /*
- * compare coordinates of two sites: allow for deviations of +/- 1;
- */
- int
- cmp_site_coord (float x1, float y1, float x2, float y2)
- {
-
- if (F_TO_INT (fabs (x1 - x2)) <= 1) {
- if (F_TO_INT (fabs (y1 - y2)) <= 1)
- return (1);
- }
- return (-1);
- }
-
-
- /*
- * comparison function for qsort():
- * sort array of struct kNNShell in order of increasing values
- * of the area of the root Site, that is, the value of the 0-th
- * element in the array aka[];
- */
- int
- cmp_root_a (t1, t2)
- /*const void *t1, *t2; */
- struct kNNShell *t1, *t2;
- {
- struct kNNShell *sk1, *sk2;
-
- sk1 = ((struct kNNShell *) t1);
- sk2 = ((struct kNNShell *) t2);
-
- return ((int) SIGN (sk1->aka[0] - sk2->aka[0]));
- }
-
-
- /*
- * comparison function for qsort():
- * sort array of tuples in order of increassing x-values
- */
- int
- compare (t1, t2)
- /*const void *t1, *t2; */
- float *t1, *t2;
- {
- float f1, f2;
-
- f1 = *((float *) t1);
- f2 = *((float *) t2);
- return ((int) SIGN (f1 - f2));
- }
-
-
- /*
- * vprintf() functions:
- * write to std output and, if option WRITE_FILE set, to file wbuf (stream)
- */
- void
- gprintf (FILE * fpOut, char *fmt,...)
- {
- va_list arg_ptr;
-
- va_start (arg_ptr, fmt);
- vprintf (fmt, arg_ptr);
- if (WRITE_FILE == 1)
- vfprintf (fpOut, fmt, arg_ptr);
- va_end (arg_ptr);
-
- }
-
-
-
- void
- fail_alloc (char *str, int code)
- {
- printf ("\n...memory alloc for %s failed\n", str);
- exit (code);
- }
-
-
- /*
- * error message
- */
- void
- exitmess (char *prompt, int status)
- {
- printf (prompt);
- printf ("\n");
-
- exit (status);
- }
-
-
- void
- usage (char *progname)
- {
- progname = last_bs (progname);
- printf ("USAGE: %s infile [-k S] [-n n] [-e] [-w] [-L]\n", progname);
- printf ("\n%s merges geometry and topology data for droplet patterns\n", progname);
- printf ("based on previous analysis by xah and xvora\n\n");
- printf ("ARGUMENTS:\n");
- printf (" infile: input filename of type .xxx (current default)\n");
- printf (" NOTE: full names of the two required input files\n");
- printf (" infile.gdt and infile.std, and optionally an\n");
- printf (" output file, are generated after stripping the\n");
- printf (" .xxx suffix; input data file types:\n");
- printf (" .gdt, generated by xah\n");
- printf (" .std, generated by xvora\n\n");
- printf ("OPTIONS:\n");
- printf (" -k S: construct k-NN shells, k<=S (default=%d)\n", KNN_MAX);
- printf (" -n n: set number of bins to n (default=%d)\n", N_BINS);
- printf (" -w: write output file of type .sgt (site geom topol)\n");
- printf (" -L: print Software License for this module\n");
- exit (1);
- }
-
-
- /*
- * skip n lines
- */
- void
- skip_n_lines (file_pointer, n_lines_to_skip)
- FILE *file_pointer;
- int n_lines_to_skip;
- {
- int i;
- char ch;
-
- for (i = 0; i < n_lines_to_skip; i++) {
- while ((ch = getc (file_pointer)) != '\n');
- }
- }
-
-
- /*
- * contract original Site array, by checking out-of-bounds flags:
- * eliminate all Sites which have been flagged
- */
- int
- contract_vsa (struct vSite **cvsa, struct vSite *vsa, int ns)
- {
- int is, nas;
- struct vSite *vS;
- nas = 0;
- for (is = 0; is < ns; is++) {
- if (((vS = (vsa + is))->eFlag == UnSet) &&
- (vS->aoiFlag == UnSet)) {
- cvsa[is] = (vsa + is);
- nas++;
- }
- }
- return (nas);
- }
-
-
- void
- main (int argc, char **argv)
- {
- int i_arg;
-
- int i, ich, is, k;
- int inn, nnn, nnn_max, ns;
- int sitenbr;
- int n_tdt;
- int eFlag, a_flag;
-
- char colon, komma, lpar, rpar;
-
- static char *inp_suffix =
- {".xxx"}; /* dummy inp file suffix */
- static char *inp_asuffix =
- {".gdt"}; /* default inp file suffix */
- static char *inp_gsuffix =
- {".std"}; /* default inp file suffix */
- static char *xxx_type =
- {".xxx"};
- static char *wsuffix =
- {".sgt"}; /* suffix for output file name */
- char *rbuf;
-
- static char rabuf[32], rgbuf[32];
- static char wbuf[20];
- char buf[32], ln_buf[LINE_LEN], fn_buf[16];
- int stop_file_io = -1;
-
- int ngdt, np, nep;
- float *a, *xs, *ys, *area, *sig;
- float xc, yc;
- struct vSite *vsa, **cvsa;
-
- FILE *fpaIn, *fpgIn, *fpOut;
-
- int idn;
- int *ondn, *ndn; /* arrays cont nof domains with n NN */
- int nbs;
- float **bs; /* ar of pntrs to bdy sep betw NN pairs */
- unsigned int **a_n; /* ar of pntrs to area of n-fold coord bubs */
- double *a_nbar; /* mean area for bubs of coord no n */
- double del_an, *sig_an; /* stand dev corresp to a_nbar */
- double ma_tdt, mr_tdt, ma_gdt, mva;
- struct Pix *dpa;
-
- int ih, nh;
- float bw, min = (float) -1.0, max = (float) -1.0;
- double mean, sdev;
- float *hbs, *ha; /* histogram of bs values */
-
-
- float **m_n; /* ar of pntrs to avrg nof NN of NN of n-fold site */
- double *m_nbar; /* mean values of m_n, as func of n */
- double del_mn, *sig_mn; /* stand dev corresp to m_nbar */
- int nas;
-
-
- /* list structs */
- struct kNNShell *sk; /* array of pntrs to lists of kNN shells */
- struct linklist *sha; /* array of kNN shells (lists) */
-
- double frms;
-
- /*
- * cmd line options:
- */
- static char *optstring = "r:k:n:ew";
-
- if (argc < 2)
- usage (argv[0]);
-
-
- rbuf = argv[1];
-
- /* construct input file names */
- ich = 0;
- while ((*(rabuf + ich) = *(rgbuf + ich) = *(rbuf + ich)) != '.')
- ich++;
- for (is = 0; is < 4; is++) {
- *(rabuf + (ich) + is) = *(inp_asuffix + is);
- *(rgbuf + (ich) + is) = *(inp_gsuffix + is);
- }
-
- if ((fpaIn = fopen (rabuf, "r")) == NULL) {
- printf ("\n...cannot open input file %s\n", rabuf);
- exit (1);
- }
- nep = 3;
- READ_AFLAG = 1;
-
- if ((fpgIn = fopen (rgbuf, "r")) == NULL) {
- printf ("\n...cannot open input file %s\n", rgbuf);
- exit (1);
- }
- READ_GFLAG = 1;
-
-
- printf ("read data from files %s and %s\n", rabuf, rgbuf);
- /* construct output file name */
- ich = 0;
- while ((*(wbuf + ich) = *(rbuf + ich)) != '.')
- ich++;
- for (is = 0; is < 4; is++)
- *(wbuf + (ich) + is) = *(wsuffix + is);
-
- /* strip input file suffix */
- for (is = 0; is < 4; is++)
- *(inp_suffix + is) = *(rbuf + (ich) + is);
-
- if (strcmp (inp_suffix, xxx_type) != 0) {
- printf ("\n...unknown input file type encountered:");
- printf (" default: %s\n", xxx_type);
- fclose (fpgIn);
- fclose (fpaIn);
- exit (1);
- }
-
- /*
- * parse command line
- */
- optind = 2;
- opterr = ON; /* give error messages */
-
-
- while ((i_arg = getopt (argc, argv, optstring)) != EOF) {
- switch (i_arg) {
- case 'k':
- printf ("...option %c: ", i_arg);
- printf ("construct %d-NN shells for all Sites\n",
- KNN_MAX = atoi (optarg));
- EVAL_KNN = ON;
- break;
-
- case 'n':
- printf ("...option %c: ", i_arg);
- printf ("set number of bins to %d\n",
- N_BINS = atoi (optarg));
- break;
-
- case 'e':
- printf ("...option %c: ", i_arg);
- printf ("disable Site status (eFlag, aoiFlag) check\n");
- CHECK_EDGE = OFF;
- break;
-
- case 'w':
- printf ("\n...option %c: ", i_arg);
- if ((fpOut = fopen (wbuf, "w")) == NULL) {
- printf ("\n...cannot open %s for writing\n",
- wbuf);
- exit (1);
- }
- printf ("write output to file %s\n", wbuf);
- WRITE_FILE = 1;
- break;
-
- case 'L':
- print_sos_lic ();
- exit (0);
-
- default:
- printf ("\n...unknown cmd line argument\n");
- exit (1);
- break;
- }
- }
- if ((READ_AFLAG == 0) || (READ_GFLAG == 0)) {
- printf ("\n...must invoke option -r to read input files!!\n");
- exit (1);
- }
-
- /*
- * merge .gdt and .std data files
- */
-
- /*
- * retrieve data from .gdt file (same type as 2-column standard file)
- */
- if ((ngdt = get_record_size (fpaIn)) > MAX_RECORD_SIZE) {
- printf ("\n...record size of %d exceeds limit of %d\n",
- ngdt, MAX_RECORD_SIZE);
- exit (1);
- }
- if ((np = get_prm_size (fpaIn)) != nep) {
- printf ("\n...n_parms = %d! expect: n_parms = %d\n",
- np, nep);
- exit (1);
- }
-
- /*
- * mem alloc
- */
- if ((a = (float *) calloc (np, sizeof (float))) == NULL)
- fail_alloc ("a", 1);
-
- if ((xs = (float *) calloc (ngdt, sizeof (float))) == NULL)
- fail_alloc ("xs", 1);
- if ((ys = (float *) calloc (ngdt, sizeof (float))) == NULL)
- fail_alloc ("ys", 1);
- if ((area = (float *) calloc (ngdt, sizeof (float))) == NULL)
- fail_alloc ("area", 1);
- if ((sig = (float *) calloc (ngdt, sizeof (float))) == NULL)
- fail_alloc ("sig", 1);
-
-
- /* fetch data */
- get_col3_data (fpaIn, np, a, ngdt, xs, ys, area, sig);
- fclose (fpaIn);
-
- #ifdef GDT_DEBUG
- printf ("\n...data from input file %s:\n", rabuf);
- printf ("\n...ngdt: %d n_parms: %d\n", ngdt, np);
-
- for (i = 0; i < np; i++)
- printf ("a[%d] = %f", i, *(a + i));
- printf ("\n");
- #endif
-
- ma_gdt = 0.0;
- for (i = 0; i < ngdt; i++) {
- #ifdef GDT_DEBUG
- printf ("xs[%d] = %f, ys[%d] = %f, area[%d] = %f\n",
- i, *(xs + i), i, *(ys + i), i, *(area + i));
- #endif
- ma_gdt += (double) (*(area + i));
- }
- ma_gdt /= (double) ngdt;
- printf ("\n...mean area ( .gdt): %lf\n", ma_gdt);
-
-
- if ((vsa = (struct vSite *) calloc (ngdt, sizeof (struct vSite))) == NULL)
- fail_alloc ("vsa", 1);
-
- /*
- * retrieve data from .std file
- */
- skip_n_lines (fpgIn, 44);
- fgets (ln_buf, LINE_LEN, fpgIn);
- sscanf (ln_buf, "%[^:]%c%s", buf, &colon, fn_buf);
- printf ("\n...data from input file %s\n", fn_buf);
-
- fgets (ln_buf, LINE_LEN, fpgIn);
- sscanf (ln_buf, "%[^:]%c%d", buf, &colon, &n_tdt);
- printf ("...total nof site entries: %d\n", n_tdt);
-
- /*
- * the following code handles .std files containing just the site
- * information (followed by EOF) as well as those with trailing
- * histogram entries
- */
- /*
- * first pass through .std file:
- * -->determine number of sites: should be identical to n_rec
- * -->determine nnn_max;
- */
- ns = 0;
- sitenbr = nnn = nnn_max = 0;
- stop_file_io = -1;
-
- skip_n_lines (fpgIn, 2);
- while (stop_file_io != 1) {
- if (fgets (ln_buf, LINE_LEN, fpgIn) != (char *) NULL) {
- sscanf (ln_buf,
- "%[^:]%c%d%[^(]%c%f%c%f%[^:]%c%d%[^:]%c%d%[^:]%c%d",
- buf, &colon, &sitenbr,
- buf, &lpar, &xc, &komma, &yc,
- buf, &colon, &eFlag,
- buf, &colon, &a_flag,
- buf, &colon, &nnn);
-
- if (sitenbr == n_tdt - 1)
- stop_file_io = 1;
-
- if (nnn > nnn_max)
- nnn_max = nnn;
- skip_n_lines (fpgIn, 1 + 1 + nnn + 2);
- ns++;
- }
- else {
- exitmess ("ERROR reading .std file\n", 1);
- }
- }
- fclose (fpgIn);
- printf ("...first pass through data found:");
- printf (" %d sites, max nnn: %d\n", ns, nnn_max);
-
- if (ns != ngdt) {
- printf ("WARNING: ");
- printf (" sz of .gdt file, %d, does not match sz of .std file, %d\n",
- ngdt, ns);
-
- exitmess ("-->remedy discrepancy before proceeding\n", 1);
-
- }
-
- for (is = 0; is < ns; is++) {
- if (((vsa + is)->nnd = (float *) calloc (nnn_max, sizeof (float))) == NULL)
- fail_alloc ("(vsa+is)->nnd", 1);
-
-
- if (((vsa + is)->nnsi = (int *) calloc (nnn_max, sizeof (int))) == NULL)
- fail_alloc ("(vsa+is)->nnsi", 1);
-
- /* initialize arrays within structures */
- for (inn = 0; inn < nnn_max; inn++) {
- (vsa + is)->nnd[inn] = (float) -1.0;
- (vsa + is)->nnsi[inn] = (int) -1;
- }
-
- if ((ondn = (int *) calloc (nnn_max + 1, sizeof (int))) == NULL)
- fail_alloc ("ondn", 1);
- if ((ndn = (int *) calloc (nnn_max + 1, sizeof (int))) == NULL)
- fail_alloc ("ndn", 1);
-
- }
-
- /*
- * second pass:
- * -->scan .std input file,
- * -->match site coords with those found in .gdt file
- */
- if ((fpgIn = fopen (rgbuf, "r")) == NULL)
- exitmess ("cannot open input file", 1);
- skip_n_lines (fpgIn, 44);
-
- skip_n_lines (fpgIn, 2 + 2);
- ns = 0;
- stop_file_io = -1;
- while (stop_file_io != 1) {
- if (fgets (ln_buf, LINE_LEN, fpgIn) != (char *) NULL) {
- sscanf (ln_buf,
- "%[^:]%c%d%[^(]%c%f%c%f%[^:]%c%d%[^:]%c%d%[^:]%c%d",
- buf, &colon, &((vsa + ns)->sitenbr),
- buf, &lpar, &((vsa + ns)->coord.x),
- &komma, &((vsa + ns)->coord.y),
- buf, &colon, &((vsa + ns)->eFlag),
- buf, &colon, &((vsa + ns)->aoiFlag),
- buf, &colon, &((vsa + ns)->nnn));
-
- if ((sitenbr = (vsa + ns)->sitenbr) == n_tdt - 1)
- stop_file_io = 1;
-
- ondn[(vsa + ns)->nnn]++;
-
- fgets (ln_buf, LINE_LEN, fpgIn);
- sscanf (ln_buf, "%[^:]%c%u",
- buf, &colon, &((vsa + ns)->v_area));
-
- skip_n_lines (fpgIn, 1);
- for (inn = 0; inn < (vsa + ns)->nnn; inn++) {
- fgets (ln_buf, LINE_LEN, fpgIn);
- sscanf (ln_buf, "%[^(]%c%d%c%f%c",
- buf, &lpar, &((vsa + ns)->nnsi[inn]),
- &colon, &((vsa + ns)->nnd[inn]), &rpar);
- }
- skip_n_lines (fpgIn, 2);
-
-
- /*
- * match site coords and extract area value (assumes y- and x-ordered data)
- */
- if (cmp_site_coord (*(xs + ns), *(ys + ns),
- (float) (vsa + ns)->coord.x,
- (float) (vsa + ns)->coord.y) == 1) {
- (vsa + ns)->area = (unsigned int) (*(area + ns));
- }
- else {
- printf ("\n...no match: ");
- printf ("(xs=%5.2f, ys=%5.2f) ",
- *(xs + ns), *(ys + ns));
- printf ("(vsx=%5.2f, vsy=%5.2f)\n",
- (vsa + ns)->coord.x, (vsa + ns)->coord.y);
- exitmess ("-->something wrong", 1);
- }
- ns++;
- }
- }
- fclose (fpgIn);
-
-
- /*
- * write output
- */
- if (WRITE_FILE == 1) {
- gprintf (fpOut, "%d %d\n", ngdt, nnn_max);
- gprintf (fpOut, "nof domains with coord no n=2(1)nnn_max: ");
- for (inn = 2; inn <= nnn_max; inn++) {
- gprintf (fpOut, " %d ", *(ondn + inn));
- }
- gprintf (fpOut, "\n");
-
- for (is = 0; is < ns; is++) {
- gprintf (fpOut, "%3d %4.1f %4.1f %u %u %d %d %2d\n",
- (vsa + is)->sitenbr,
- (vsa + is)->coord.x, (vsa + is)->coord.y,
- (vsa + is)->v_area, (vsa + is)->area,
- (vsa + is)->eFlag, (vsa + is)->aoiFlag,
- (vsa + is)->nnn);
-
- for (inn = 0; inn < (vsa + is)->nnn; inn++) {
- gprintf (fpOut, " %5d %5.1f\n",
- (vsa + is)->nnsi[inn], (vsa + is)->nnd[inn]);
- }
- }
- }
-
-
- /*
- * contract Site array vsa by eliminating all Sites which have been
- * flagged out-of-bounds (eFlag, aoiFlag)
- *
- * following code (CONTRACT == 1) is largely untested: it might be useful
- * to perform this contraction to avoid having to check, as done currently
- * for all later functions (in anal_gt.c, knns.c, etc) whether original Sites
- * have been flagged out-of-bounds; this checking eliminates such Sites as
- * reference (or ``root'') Sites, but leaves them present as possible kNN
- * of other reference Sites, while contraction would remove them altogether
- *
- * note: performing the Site checking affects the counts of nnn, maintained
- * in the index array ndn: entries will generally differ from those
- * in ondn; to make subsequent array alloc more robust (independent
- * of whether or not Site checking was enforced in pertinent functions
- * (e.g. p_of_a(), m_n(), etc), arrays are slightly over-dimensioned
- * by relying on ondn, the original entries in ndn with all Sites
- * admitted;
- */
- if (CONTRACT == 1) {
- if ((cvsa = (struct vSite **) calloc (ns, sizeof (struct vSite *))) == NULL)
- fail_alloc ("cvsa", 1);
-
- ns = contract_vsa (cvsa, vsa, ns);
- printf ("\n...Site array contraction leaves %d active Sites\n", ns);
-
- if ((cvsa = (struct vSite **) realloc (cvsa, ns * sizeof (struct vSite *))) ==
- NULL)
- fail_alloc ("cvsa(realloc)", 1);
-
-
- for (inn = 0; inn < nnn_max; inn++)
- ndn[inn] = 0;
- nnn_max = 0;
- for (is = 0; is < ns; is++) {
- if (cvsa[is]->nnn > nnn_max)
- nnn_max = cvsa[is]->nnn;
- ndn[cvsa[is]->nnn]++;
- }
- printf ("%d %d\n", ns, nnn_max);
- printf ("nof domains with coord no n=2(1)nnn_max: ");
- for (inn = 2; inn <= nnn_max; inn++) {
- printf (" %d ", *(ndn + inn));
- }
- printf ("\n");
-
- for (is = 0; is < ns; is++) {
- printf ("%3d %4.1f %4.1f %u %2d\n",
- cvsa[is]->sitenbr,
- cvsa[is]->coord.x, cvsa[is]->coord.y,
- cvsa[is]->area, cvsa[is]->nnn);
-
- for (inn = 0; inn < cvsa[is]->nnn; inn++) {
- printf (" %5d %5.1f\n",
- cvsa[is]->nnsi[inn], cvsa[is]->nnd[inn]);
- }
- }
- }
-
-
- /*
- * extract various geometrical and topological quantities
- * describing bubble domain patterns
- */
-
- /*
- * joint probability distribution of coordination number, n, and area, A
- *
- * --> examine number of NNs as a function of domain area (->Lewis' law)
- */
-
- if ((a_n = (unsigned int **) calloc (nnn_max, sizeof (unsigned int *))) == NULL)
- fail_alloc ("a_n", 1);
-
- for (inn = 0; inn < nnn_max; inn++) {
- if ((a_n[inn] = (unsigned int *) calloc (ondn[inn] + 1, sizeof (unsigned
- int))) == NULL)
- fail_alloc ("a_n[inn]", 1);
-
- }
-
- if ((a_nbar = (double *) calloc (nnn_max + 1, sizeof (double))) == NULL)
- fail_alloc ("a_nbar", 1);
-
- if ((sig_an = (double *) calloc (nnn_max + 1, sizeof (double))) == NULL)
- fail_alloc ("sig_an", 1);
-
- if ((ndn = (int *) calloc (nnn_max + 1, sizeof (int))) == NULL)
- fail_alloc ("ndn", 1);
-
- ma_tdt = p_of_nA (ndn, a_n, ns, vsa);
-
- gprintf (fpOut, "\nmean bubble domain area (. tdt): %lf\n", ma_tdt);
- gprintf (fpOut, "domains grouped by coord no n=2(1)%d:\n", nnn_max);
- for (inn = 2; inn <= nnn_max; inn++) {
- for (idn = 0; idn < ndn[inn]; idn++) {
- if (SHOW_ALL == 1) {
- gprintf (fpOut, "...%5u ", *(a_n[inn] + idn));
- if ((idn + 1) % 8 == 0)
- gprintf (fpOut, "\n");
- }
- *(a_nbar + inn) += (double) (*(a_n[inn] + idn));
- }
- if (idn > 1) {
- *(a_nbar + inn) /= (double) idn;
-
- gprintf (fpOut, "\n nof NN: %2d -- <A_n> ", inn);
- gprintf (fpOut, "(mean of %d): %6.1lf \n",
- idn, *(a_nbar + inn));
- gprintf (fpOut, "\t -- <A_n>/<A>: %lf\n",
- (double) (*(a_nbar + inn)) / ma_tdt);
-
- /* standard deviation */
- for (idn = 0; idn < ndn[inn]; idn++) {
- del_an = *(a_n[inn] + idn) - *(a_nbar + inn);
- *(sig_an + inn) += del_an * del_an;
- }
- *(sig_an + inn) = sqrt (*(sig_an + inn) / (double) (idn - 1));
- gprintf (fpOut, "\t -- sigma_an: %lf\n\n",
- (double) (*(sig_an + inn)) / ma_tdt);
- }
- }
-
-
- /*
- * log vPoly area vs bubble area
- */
- gprintf (fpOut, "\n...bubble domain area vs Voronoi polygon area\n");
- if ((dpa = (struct Pix *) calloc (ns, sizeof (struct Pix))) == NULL)
- fail_alloc ("dpa", 1);
-
- nas = a_vs_vPa (dpa, ns, vsa, &ma_tdt, &mva);
- gprintf (fpOut, "\tmean Vor poly area: %6.1lf:\n", mva);
- gprintf (fpOut, "\t mean bubble area: %6.1lf:", ma_tdt);
-
- gprintf (fpOut, "\t(%d unflagged Sites only)\n", nas);
- for (is = 0; is < ns; is++) {
- if (((dpa + is)->x > -1.0) && ((dpa + is)->y > -1.0)) {
- gprintf (fpOut, "...Site %3d: %f %f\n",
- (vsa + is)->sitenbr, (dpa + is)->x, (dpa + is)->y);
- }
- }
-
-
- /*
- * boundary separation between NN domains: s_ij = d_ij - r_i - r_j
- * note: each s_ij will occur twice
- */
- if ((bs = (float **) calloc (ns, sizeof (float *))) == NULL)
- fail_alloc ("bs", 1);
-
- for (is = 0; is < ns; is++) {
- if ((bs[is] = (float *) calloc ((vsa + is)->nnn, sizeof (float))) == NULL)
- fail_alloc ("bs[is]", 1);
-
- }
-
- nbs = eval_sij (bs, ns, vsa);
- gprintf (fpOut, "...%d values of pairwise NN bdy separations\n", nbs);
-
- for (is = 0; is < ns; is++) {
- printf ("site %3d: ", (vsa + is)->sitenbr);
- for (inn = 0; inn < (vsa + is)->nnn; inn++) {
- printf ("...%6.1f ", *(bs[is] + inn));
- if ((inn + 1) % 10 == 0)
- printf ("\n");
- }
- printf ("\n");
- }
-
- /*
- * evaluate histogram of boundary separations, normalized to
- * the mean bubble radius, <R> = sqrt( <A>/PI );
- * -->note: each s_ij is counted twice
- */
- nh = 0;
- for (is = 0; is < ns; is++)
- nh += (vsa + is)->nnn;
-
- if ((hbs = (float *) calloc (nh, sizeof (float *))) == NULL)
- fail_alloc ("hbs", 1);
-
- if ((ha = (float *) calloc ((size_t) N_BINS, sizeof (float))) == NULL)
- fail_alloc ("hist\n", 1);
-
- /*
- * copy and normalize bdy separation values, eliminating entries
- * of 0.0 indicating that corresponding ref Site is out of bounds
- */
-
- ih = 0;
- for (is = 0; is < ns; is++) {
- for (inn = 0; inn < (vsa + is)->nnn; inn++) {
- if (*(bs[is] + inn) > 0.0) {
- *(hbs + ih) = *(bs[is] + inn);
- ih++;
- }
- }
- }
- printf ("\n...nbs: %d, nh: %d, ih: %d\n", nbs, nh, ih);
-
- /*
- * realloc
- */
- if (ih < nh) {
- if ((hbs = (float *) realloc (hbs, ih * sizeof (float *))) == NULL)
- fail_alloc ("hbs (realloc)", 1);
- }
- nh = ih;
-
- /*
- * evaluate statistics
- */
- gprintf (fpOut, "\n...statistics for boundary separation data\n");
- mean = find_mean (hbs, nh);
- sdev = find_sigma (hbs, nh, mean);
- mr_tdt = sqrt (ma_tdt / PI);
- gprintf (fpOut, "\tmean: %lf, mean/<R>: %lf\n", mean, mean / mr_tdt);
- gprintf (fpOut, "\tsdev: %lf, sdev/<R>: %lf\n", sdev, sdev / mr_tdt);
- gprintf (fpOut, "\t(in units of mean radius, <R> = %lf)\n", mr_tdt);
-
- /*
- * prepare to evaluate histogram: normalize and sort
- */
- for (ih = 0; ih < nh; ih++)
- *(hbs + ih) /= (float) mean;
- #if defined(LINUX)
- qsort (hbs, nh, sizeof (float), (__compar_fn_t) compare);
- #else
- qsort (hbs, nh, sizeof (float), compare);
- #endif
-
- #ifdef SHOW_HSORT
- printf ("\n...sorted data:\n");
- for (ih = 0; ih < nh; ih++)
- printf (" hbs[%d] = %f\n", ih, *(hbs + ih));
- #endif
-
- HIST_HEADER = BS_HIST;
- if (MIN_SET == 0)
- min = (float) NSIJ_MIN;
- if (MAX_SET == 0)
- max = (float) NSIJ_MAX;
- if ((-1.0e-10 < (min - max)) && ((min - max) < 1.0e-10))
- min = max;
- bw = (max - min) / ((float) (N_BINS - 1));
-
- printf ("\n...construct histogram of %d entries...\n", nh);
- if (bw != 0.0)
- construct_shist (nh, hbs, ha, bw, min);
-
- gprintf (fpOut, "%s\n", HIST_HEADER);
- gprintf (fpOut, "...min/mean: %f, bw: %f, max/mean: %f\n", min, bw, max);
- gprintf (fpOut, "...fractions\n");
- for (i = 0; i < N_BINS; i++) {
- gprintf (fpOut, " %6.2f", *(ha + i) / (float) nbs);
- /* gprintf(fpOut, " %6.2f", *(ha+i) ); */
- if ((i + 1) % 10 == 0)
- gprintf (fpOut, "\n");
- }
-
-
- free (a);
- free (area);
- free (xs);
- free (ys);
- free (sig);
-
- for (inn = 0; inn < nnn_max; inn++)
- free (a_n[inn]);
- free (a_n);
- free (a_nbar);
- free (sig_an);
-
- free (dpa);
-
- for (is = 0; is < ns; is++)
- free (bs[is]);
- free (bs);
- free (hbs);
- free (ha);
-
-
- /*
- * spatial correlations in the field A = A(r):
- */
-
- /*
- * evaluate the average number, m(n), of NN of the NN of an n-fold
- * coordinated site (->Aboav-Weaire law for cellular structures)
- */
-
- if ((m_n = (float **) calloc (nnn_max + 1, sizeof (float *))) == NULL)
- fail_alloc ("m_n", 1);
-
- for (inn = 0; inn < nnn_max; inn++) {
- if ((m_n[inn] = (float *) calloc (ondn[inn] + 1, sizeof (float))) == NULL)
- fail_alloc ("m_n[inn]", 1);
-
- }
- if ((m_nbar = (double *) calloc (nnn_max + 1, sizeof (double))) == NULL)
- fail_alloc ("m_nbar", 1);
-
- if ((sig_mn = (double *) calloc (nnn_max + 1, sizeof (double))) == NULL)
- fail_alloc ("sig_mn", 1);
-
- for (inn = 0; inn <= nnn_max; inn++)
- *(ndn + inn) = 0;
-
- nas = m_of_n (ndn, m_n, ns, vsa);
-
- gprintf (fpOut, "\n...average nof NN of the NN of n-fold sites\n");
- gprintf (fpOut, "\t grouped by coord no n=2(1)%d:\n", nnn_max);
- for (inn = 2; inn <= nnn_max; inn++) {
- for (idn = 0; idn < ndn[inn]; idn++) {
- if (SHOW_ALL == 1) {
- gprintf (fpOut, "...%5.2f ", *(m_n[inn] + idn));
- if ((idn + 1) % 8 == 0)
- gprintf (fpOut, "\n");
- }
- *(m_nbar + inn) += (double) (*(m_n[inn] + idn));
- }
- if (idn > 1) {
- *(m_nbar + inn) /= (double) idn;
-
- gprintf (fpOut, "\n nof NN: %2d -- <m_n> ", inn);
- gprintf (fpOut, "(mean of %d): %5.2lf ",
- idn, *(m_nbar + inn));
-
- /* standard deviation */
- for (idn = 0; idn < ndn[inn]; idn++) {
- del_mn = *(m_n[inn] + idn) - *(m_nbar + inn);
- *(sig_mn + inn) += del_mn * del_mn;
- }
- *(sig_mn + inn) = sqrt (*(sig_mn + inn) / (double) (idn - 1));
- gprintf (fpOut, " -- sigma_mn: %lf\n\n",
- (double) (*(sig_mn + inn)));
- }
- }
-
-
- /*
- * given the area, A0, of a bubble domain at location (x0, y0),
- * evaluate the average, <Ak>, of areas of bubbles in the k-th NN
- * shell of bubble 0, as a function of k
- */
-
- /*
- * construct kNN shells (topology: see also: xvora)
- */
- if (EVAL_KNN == 1) {
- if ((sk = (struct kNNShell *) calloc (ns, sizeof (struct kNNShell))) == NULL)
- fail_alloc ("sk", 1);
-
-
- for (is = 0; is < ns; is++) {
- if (((sk + is)->aka = (double *) calloc (KNN_MAX, sizeof (double))) ==
- NULL)
- fail_alloc ("sk->aka", 1);
- }
- for (is = 0; is < ns; is++) {
- if (((sk + is)->tctc = (double *) calloc (KNN_MAX, sizeof (double))) ==
- NULL)
- fail_alloc ("sk->tctc", 1);
- }
-
-
- if ((sha = (struct linklist *) calloc (KNN_MAX, sizeof (struct linklist)))
- == NULL)
- fail_alloc ("sha", 1);
-
- gprintf (fpOut, "...constr kNN shells up to k=%d\n", KNN_MAX);
- frms = construct_kNNs (ns, vsa, sha, sk);
- gprintf (fpOut, "...avrg fractal meas of set: %lf\n", frms);
-
- gprintf (fpOut, "\n...<A_k>/<A_(k-1)> (<A> = %lf):\n", ma_tdt);
- gprintf (fpOut, "\t(sorted in order of area of root Site)\n");
- gprintf (fpOut, "\t(unflagged Sites only)\n");
-
- /*
- * sort array sk in order of increasing areas associated with the root Site
- *
- * note: sorting scrambles the original Site indices so that flagged
- * Sites are no longer correctly identified;
- */
- #if defined(LINUX)
- qsort (sk, (size_t) ns, sizeof (struct kNNShell), (__compar_fn_t) cmp_root_a);
- #else
- qsort (sk, (size_t) ns, sizeof (struct kNNShell), cmp_root_a);
- #endif
-
- for (is = 0; is < ns; is++) {
- gprintf (fpOut, "...Site %3d ", (sk + is)->sitenbr);
- gprintf (fpOut, "A: %6.2lf A/<A>: %6.2lf ",
- (sk + is)->aka[0], (sk + is)->aka[0] / ma_tdt);
-
- /* normalize <A>_kNN by average over prev shell */
- for (k = 1; k < (sk + is)->kNN; k++) {
- gprintf (fpOut, "...%6.2lf ",
- (sk + is)->aka[k] / (sk + is)->aka[k - 1]);
-
- if ((k + 1) % 8 == 0)
- gprintf (fpOut, "\n");
- }
- gprintf (fpOut, "\n");
- }
-
- #ifdef FRMS_DEBUG
- KNN_MAX = 0;
- for (is = 0; is < ns; is++) {
- printf ("Site %3d: ", (vsa + is)->sitenbr);
- if (((vsa + is)->eFlag == UnSet) &&
- ((vsa + is)->aoiFlag == UnSet)) {
- printf ("kNN: %3d, frms: %6.3lf\n",
- (sk + is)->kNN, (sk + is)->frms);
-
- if ((sk + is)->kNN > KNN_MAX)
- KNN_MAX = (sk + is)->kNN;
- }
- else { /* Site flagged out-of-bounds */
- if ((sk + is)->kNN == 0)
- printf (" out of bounds: -->ignored\n");
- else
- printf (" something wrong\n");
- }
- printf ("\tactual KNN_MAX: %3d\n", KNN_MAX);
- }
- #endif
-
-
- #ifdef KNNS_ARRAY_VER
- for (is = 0; is < ns; is++) {
- printf ("Site %3d\n", (vsa + is)->sitenbr);
- for (k = 0; k < (sk + is)->kNN; k++)
- show_kNN_list (&((sk + is)->sha[k]), k);
- }
- #endif
- }
-
-
- /* dealloc resources */
- fclose (fpOut);
-
- free (vsa);
-
- for (inn = 0; inn <= nnn_max; inn++)
- free (m_n[inn]);
- free (m_n);
- free (m_nbar);
- free (sig_mn);
-
- if (EVAL_KNN == 1) {
- for (is = 0; is <= ns; is++)
- free ((sk + is)->aka);
- for (is = 0; is <= ns; is++)
- free ((sk + is)->tctc);
- free (sk);
- free (sha);
- }
-
- free (ondn);
- free (ndn);
- if (CONTRACT == 1)
- free (cvsa);
- }
-